package dispatcher;
import gamer.Gamer;

import java.util.LinkedList;

import battlestein.GameEngine;
/**
 * 
 * @author LocoRocoBattleStein
 *
 */
public class LocalDispatcher implements InterfaceDispatcher{

	private GameEngine GE;
	private LinkedList<Gamer> gamers;
	
	public LocalDispatcher(GameEngine GE) {
		this.GE = GE;
		gamers = new LinkedList<Gamer>();
	}
	
	public void run() {
		
	}
	
	public void setNetwork(String network) {
		GE.setNetwork(network);
	}
	
	public void newPlayer() {
		GE.newPlayer();
	}
	
	public void startGame(int idPlayer) {
		for(Gamer g : gamers) {
			g.startGame(idPlayer);
		}
	}

	public void updateTower(int id, int idPlayer, int x, int y) {
		for(Gamer g : gamers) {
			g.updateTower(id, idPlayer, x, y);
		}
	}
	
	public void updateTower(int id, int rate, int range, int life, int velocity) {
		for(Gamer g : gamers) {
			g.updateTower(id, rate, range, life, velocity);
		}
	}
	
	public void updateDestBase(int src, int dest) {
		for(Gamer g : gamers) {
			g.updateDestBase(src, dest);
		}
	}
	
	public void setDestBase(int src, int dest) {
		synchronized(GE) {
			GE.setDestBase(src, dest);
		}
	}

	public void upgradeTower(int id, int rate, int range, int life, int velocity) {
		synchronized(GE) {
			GE.upgradeTower(id, rate, range, life, velocity);
		}
	}

	public void addTower(int id, int idPlayer, int x, int y) {
		synchronized(GE) {
			GE.addTower(id, idPlayer, x, y);
		}
	}


	public GameEngine getGE() {
		return GE;
	}
	public void setGE(GameEngine GE) {
		this.GE = GE;
	}

	public Gamer getGamers(int i) {
		return gamers.get(i);
	}
	public void setGamer(Gamer gamer) {
			this.gamers.add(gamer);
	}

}
